from ronglian_sms_sdk import SmsSDK
from random import randint, choice
import random
import time

accId = '2c948876856178260185876131120425'
accToken = '8a8e117bd66b405384627fe51d85ae7a'
appId = '2c94887685617826018587613216042c'



def generate_code():

    # 定义一个种子，从这里面随机拿出一个值，可以是字母
    seeds = "1234567890"
    # 定义一个空列表，每次循环，将拿到的值，加入列表
    random_num = []
    # choice函数：每次从seeds拿一个值，加入列表
    for i in range(4):
        random_num.append(choice(seeds))
    # 将列表里的值，变成四位字符串
    return "".join(random_num)


def send_message(mobile):
    random_num=generate_code()
    sdk = SmsSDK(accId, accToken, appId)
    tid = '1'
    # mobile = '13692610489'
    mobile = mobile
    datas = (random_num,'5')
    resp = sdk.sendMessage(tid, mobile, datas)
    print(resp)
    return random_num

# for i in range(5):
#     send_message('13692610489')
#     time.sleep(1)
